package com.gsta.cdn.cdr.mapper;

import com.baomidou.mybatisplus.mapper.BaseMapper;
import com.gsta.cdn.cdr.entity.ChannelConcurrent;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

@Mapper
@Component(value = "ConcurrentHotMapper")
public interface ConcurrentHotMapper extends BaseMapper<ChannelConcurrent> {

    @Select("<script>" +
            "SELECT Date,HotNum,CIDNum FROM ConcurrentHotAll WHERE Percent=#{Percent} AND Date LIKE CONCAT(#{Date},'%') "+
            "</script>")
    List<Map<String, Object>> ConcurrentHotHotNum(@Param("Date") String Date, @Param("Percent") String Percent);

    @Select("<script>" +
            "SELECT Date,HotNum,Percent,CIDNum,HotCount,HotCountPercent " +
            "FROM ConcurrentHotAll WHERE Percent=#{Percent} AND Date LIKE CONCAT(#{Date},'%') " +
            "ORDER BY Date " +
            "LIMIT #{page},#{pageSize} "+
            "</script>")
    List<Map<String, Object>> ConcurrentHotData(@Param("Date") String Date, @Param("Percent") String Percent,@Param("page") int page,
                                                @Param("pageSize") int pageSize);

    @Select("<script> " +
            "SELECT COUNT(*) AS count FROM ( " +
            "SELECT Date,HotNum,Percent,CIDNum,HotCount,HotCountPercent " +
            "FROM ConcurrentHotAll WHERE Percent=#{Percent} AND Date LIKE CONCAT(#{Date},'%'))a "+
            "</script>")
    int ConcurrentHotDataCount(@Param("Date") String Date, @Param("Percent") String Percent);

    @Select("<script> " +
            "SELECT DISTINCT Area FROM ConcurrentHotAreaPopName  " +
            "WHERE Date LIKE CONCAT(#{Date},'%') " +
            "ORDER BY Area  "+
            "</script>")
    List<Map<String, Object>> ConcurrentHotArea(@Param("Date") String Date, @Param("Percent") String Percent);

    @Select("<script> " +
            "SELECT DISTINCT PopName FROM ConcurrentHotAreaPopName  " +
            "WHERE Date LIKE CONCAT(#{Date},'%') AND  Area=#{Area} "+
            "</script>")
    List<Map<String, Object>> ConcurrentHotAreaPopName(@Param("Date") String Date, @Param("Percent") String Percent,@Param("Area") String Area);

    @Select("<script> " +
            "SELECT * FROM ConcurrentHotAreaPopName  " +
            "WHERE Date LIKE CONCAT(#{Date},'%') AND  Area=#{Area} AND  PopName=#{PopName} AND Percent=#{Percent} "+
            "ORDER BY Date " +
            "LIMIT #{page},#{pageSize} "+
            "</script>")
    List<Map<String, Object>> ConcurrentHotByAreaPopName(@Param("Date") String Date,@Param("Area") String Area, @Param("PopName") String PopName,
                                                         @Param("Percent") String Percent,@Param("page") int page,@Param("pageSize") int pageSize);

    @Select("<script> " +
            "SELECT COUNT(*) AS count FROM ( " +
            "SELECT * FROM ConcurrentHotAreaPopName  " +
            "WHERE Date LIKE CONCAT(#{Date},'%') AND  Area=#{Area} AND  PopName=#{PopName} AND Percent=#{Percent} )a "+
            "</script>")
    int ConcurrentHotByAreaPopNameCount(@Param("Date") String Date,@Param("Area") String Area, @Param("PopName") String PopName, @Param("Percent") String Percent);

    @Select("<script> " +
            "SELECT * FROM ConcurrentHotArea  " +
            "WHERE Date LIKE CONCAT(#{Date},'%') AND  Area=#{Area} AND  Percent=#{Percent} "+
            "ORDER BY Date " +
            "LIMIT #{page},#{pageSize} "+
            "</script>")
    List<Map<String, Object>> ConcurrentHotByArea(@Param("Date") String Date,@Param("Area") String Area,
                                                         @Param("Percent") String Percent,@Param("page") int page,@Param("pageSize") int pageSize);

    @Select("<script> " +
            "SELECT COUNT(*) AS count FROM ( " +
            "SELECT * FROM ConcurrentHotArea  " +
            "WHERE Date LIKE CONCAT(#{Date},'%') AND  Area=#{Area}  AND Percent=#{Percent} )a "+
            "</script>")
    int ConcurrentHotByAreaCount(@Param("Date") String Date,@Param("Area") String Area, @Param("Percent") String Percent);


    @Select("<script> " +
            "SELECT * FROM ConcurrentHotPopName  " +
            "WHERE Date LIKE CONCAT(#{Date},'%')  AND  PopName=#{PopName} AND Percent=#{Percent} "+
            "ORDER BY Date " +
            "LIMIT #{page},#{pageSize} "+
            "</script>")
    List<Map<String, Object>> ConcurrentHotByPopName(@Param("Date") String Date, @Param("PopName") String PopName,@Param("Percent") String Percent,
                                                     @Param("page") int page,@Param("pageSize") int pageSize);

    @Select("<script> " +
            "SELECT COUNT(*) AS count FROM ( " +
            "SELECT * FROM ConcurrentHotPopName  " +
            "WHERE Date LIKE CONCAT(#{Date},'%')  AND  PopName=#{PopName} AND Percent=#{Percent} )a "+
            "</script>")
    int ConcurrentHotByPopNameCount(@Param("Date") String Date, @Param("PopName") String PopName, @Param("Percent") String Percent);


}
